﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using MeizuSDK.Presentation;
using System.Drawing;
using MeizuSDK.Core;
using System.Diagnostics;

namespace Demo
{
    class PhoneWindow : DemoWindowBase
    {
        TextBox phoneNumberTextBox = new TextBox();
        TextBox messageTextBox = new TextBox();
        Button sendMessageButton = new Button();
        Button callButton = new Button();

        Button gprsButton = new Button();

        public PhoneWindow()
        {
            phoneNumberTextBox.Location = new Point(10, 10);
            phoneNumberTextBox.Size = new Size(400, 60);
            phoneNumberTextBox.Text = "10086";

            messageTextBox.Location = new Point(10, 80);
            messageTextBox.Size = new Size(400, 60);
            messageTextBox.Text = "10086";

            sendMessageButton.Text = "Send SMS";
            sendMessageButton.Location = new Point(10, 150);
            sendMessageButton.Click += new EventHandler(sendMessageButton_Click);

            callButton.Text = "Call";
            callButton.Location = new Point(10, 250);
            callButton.Click += new EventHandler(callButton_Click);

            gprsButton.Text = "GPRS拨号";
            gprsButton.Location = new Point(10, 350);
            gprsButton.Click += new EventHandler(gprsButton_Click);

            Controls.Add(phoneNumberTextBox);
            Controls.Add(messageTextBox);
            Controls.Add(sendMessageButton);
            Controls.Add(callButton);
            Controls.Add(gprsButton);
        }

        void sendMessageButton_Click(object sender, EventArgs e)
        {
            Telephony.SendSMSMessage(phoneNumberTextBox.Text, messageTextBox.Text);
        }

        void callButton_Click(object sender, EventArgs e)
        {
            Telephony.MakePhoneCall(phoneNumberTextBox.Text);

            this.phoneNumberTextBox.SetFocus(false);
            this.messageTextBox.SetFocus(false);
        }

        void gprsButton_Click(object sender, EventArgs e)
        {
            bool r = Networking.GprsConnect(HWnd);
            if (r)
                MessageBox.Show("拨号成功");
            else
                MessageBox.Show("拨号失败");

            r = Networking.GprsDisconnect(HWnd);

            if (r)
                MessageBox.Show("断开成功");
            else
                MessageBox.Show("断开失败");
        }
    }
}
